/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pigx.strategy.dto;


import lombok.Data;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * StrategyContractAddDTO
 *
 * @since 2022-11-23 15:15:20
 */
@Data
public class StrategyContractAddDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 策略组id
     */
    @NotNull(message = "参数异常，groupId为空")
    private Long groupId;

    /**
     * 平台id
     */
    @NotNull(message = "参数异常，platformId为空")
    private Long platformId;

    /**
     * 币对名称
     */
    @NotBlank(message = "参数异常，symbolName为空")
    @Size(max = 100, message = "参数异常，symbolName最大长度为100")
    private String symbolName;

    /**
     * 产品id
     */
    @NotNull(message = "参数异常，productId为空")
    private Long productId;

    /**
     * 首仓方向（0做多、1做空、2双向）首次下单仓位方向。双向时同时下多空两个开仓单
     */
    @NotBlank(message = "参数异常，side为空")
    private String side;

    /**
     * 订单数量任务总共可下开仓单数例，做单方向为双向时，开多空两个仓位，此时下单数量为2。补仓时如果需要锁仓，累计下单数量+2
     */
    @NotNull(message = "参数异常，orderNum为空")
    @Min(value = 0, message = "参数异常，orderNum最小为0")
    @Max(value = 2000000000, message = "参数异常，orderNum最大为2000000000")
    private Integer orderNum;

    /**
     * 杠杆倍数
     */
    @NotNull(message = "参数异常，multiple为空")
    @DecimalMin(value = "0", message = "参数异常，multiple最小为0")
    @DecimalMax(value = "9999.99", message = "参数异常，multiple最大为9999.99")
    private BigDecimal multiple;

    /**
     * 首仓张数首次开仓数量
     */
    @NotNull(message = "参数异常，firstNum为空")
    @Min(value = 0, message = "参数异常，firstNum最小为0")
    @Max(value = 2000000000, message = "参数异常，firstNum最大为2000000000")
    private Integer firstNum;

    /**
     * 价格波动比例（%）补仓的价格波动判断依据。例，补仓比例为10%，开首仓后，如果价格波动大于等于10%，开始进行首次补仓。价格上涨10%时补空仓，下跌10%时补多仓，补已有持仓数量后续补仓时，根据首次补仓方向判断价格向亏损侧又波动一定比例后，补首次补仓方向仓位。比如下单方向双向，首仓张数为1，补仓增幅为1%，首次补空仓补2张。当价格在上次补仓的成交均价基础上又上涨（根据补仓方向的亏损侧判断）11%后，进行第二次补仓，补已有持仓数量，即1 + 2 + 1 = 4张可以进行锁仓时，反向额外根据锁仓百分比、双向仓位总数量补仓
     */
    @NotNull(message = "参数异常，fluctuationRatio为空")
    @DecimalMin(value = "0", message = "参数异常，fluctuationRatio最小为0")
    @DecimalMax(value = "9999.99", message = "参数异常，fluctuationRatio最大为9999.99")
    private BigDecimal fluctuationRatio;

    /**
     * 价格波动增幅（%）每次补仓的价格波动偏移量，首次补仓不计算该数值。例，补仓增幅为1%，已补空仓3次，价格在上次补仓的成交均价基础上又下跌（根据补仓方向的盈利侧判断） 10% + 1% * 3 时，进行补仓
     */
    @NotNull(message = "参数异常，fluctuationIncrease为空")
    @DecimalMin(value = "0", message = "参数异常，fluctuationIncrease最小为0")
    @DecimalMax(value = "9999.99", message = "参数异常，fluctuationIncrease最大为9999.99")
    private BigDecimal fluctuationIncrease;

    /**
     * 利润回调比例（%）盈利后，双向仓位利润率回调达到n%时，平仓。例，回调比例为20%，利润率最高达到了15%，当利润率回落到12%时，进行平仓
     */
    @NotNull(message = "参数异常，callbackRatio为空")
    @DecimalMin(value = "0", message = "参数异常，callbackRatio最小为0")
    @DecimalMax(value = "9999.99", message = "参数异常，callbackRatio最大为9999.99")
    private BigDecimal callbackRatio;

    /**
     * 利润回降比例（%）记录开仓后最高/低（根据持仓方向判断）价格，盈利后当价格回调达到n%时，平仓。例，回降比例为10%，首仓800开多，盈利方向为多仓，开仓后记录的最高价格为1000，当价格跌落到900时，进行平仓
     */
    @NotNull(message = "参数异常，fallbackRatio为空")
    @DecimalMin(value = "0", message = "参数异常，fallbackRatio最小为0")
    @DecimalMax(value = "9999.99", message = "参数异常，fallbackRatio最大为9999.99")
    private BigDecimal fallbackRatio;

    /**
     * 止盈比例（%）盈利后继续盈利，如果回调到止盈比例，进行平仓。例，止盈比例为10%，利润率达到10%并且仍然在盈利时，不进行平仓。假如利润率在上涨到15%后，又重新回落到10%，进行平仓
     */
    @NotNull(message = "参数异常，stopProfitRatio为空")
    @DecimalMin(value = "0", message = "参数异常，stopProfitRatio最小为0")
    @DecimalMax(value = "9999.99", message = "参数异常，stopProfitRatio最大为9999.99")
    private BigDecimal stopProfitRatio;

    /**
     * 价格区间最大值价格区间的最大值，当价格大于等于该值时，停止补仓操作
     */
    @DecimalMin(value = "0", message = "参数异常，maxPrice最小为0")
    @DecimalMax(value = "2000000000", message = "参数异常，maxPrice最大为2000000000")
    private BigDecimal maxPrice;

    /**
     * 价格区间最小值价格区间的最小值，当价格小于等于该值时，停止补仓操作
     */
    @DecimalMin(value = "0", message = "参数异常，minPrice最小为0")
    @DecimalMax(value = "2000000000", message = "参数异常，minPrice最大为2000000000")
    private BigDecimal minPrice;

    /**
     * 止盈数值盈利大于等于该数值时，进行平仓
     */
    @DecimalMin(value = "0", message = "参数异常，stopProfitValue最小为0")
    @DecimalMax(value = "2000000000", message = "参数异常，stopProfitValue最大为2000000000")
    private BigDecimal stopProfitValue;

    /**
     * 止损数值亏损大于等于该数值时，进行平仓
     */
    @NotNull(message = "参数异常，stopLostValue为空")
    @DecimalMin(value = "0", message = "参数异常，stopLostValue最小为0")
    @DecimalMax(value = "2000000000", message = "参数异常，stopLostValue最大为2000000000")
    private BigDecimal stopLostValue;

    /**
     * 余额限制用户交易所账户余额不足时，无法开启/继续执行策略
     */
    @DecimalMin(value = "0", message = "参数异常，balanceLimit最小为0")
    @DecimalMax(value = "2000000000", message = "参数异常，balanceLimit最大为2000000000")
    private BigDecimal balanceLimit;

    /**
     * 锁仓启用时机n次补仓后，补仓的同时需要额外根据锁仓百分比补反向仓位例，锁仓仓位的值为3，则在第3次补仓时，根据锁仓百分比为反向仓位进行补仓
     */
    @Min(value = 0, message = "参数异常，lockStart最小为0")
    @Max(value = 2000000000, message = "参数异常，lockStart最大为2000000000")
    private Integer lockStart;

    /**
     * 锁仓比例（%）根据双向仓位已有总数量的百分比进行锁仓操作
     */
    @DecimalMin(value = "0", message = "参数异常，fallbackRatio最小为0")
    @DecimalMax(value = "9999.99", message = "参数异常，fallbackRatio最大为9999.99")
    private BigDecimal lockRatio;

    /**
     * 正向止盈启用时机
     */
    @Min(value = 1, message = "参数异常，forwardStopStart最小为1")
    @Max(value = 2000000000, message = "参数异常，forwardStopStart最大为2000000000")
    private Integer forwardStopStart;

    /**
     * 下单重试价格波动
     */
    @DecimalMin(value = "0", message = "参数异常，orderRetryPriceFluctuation最小为0")
    @DecimalMax(value = "9999.99", message = "参数异常，orderRetryPriceFluctuation最大为9999.99")
    private BigDecimal orderRetryPriceFluctuation;

    /**
     * 下单重试最大次数
     */
    @Min(value = 1, message = "参数异常，orderRetryMax最小为1")
    @Max(value = 2000000000, message = "参数异常，orderRetryMax最大为2000000000")
    private Integer orderRetryMax;
}
